package cn.service.marketingService.MarketingServiceImpl;

import cn.service.marketingService.FlashSaleProductService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.*;
import entity.marketingEntity.FlashAddCondition;
import entity.marketingEntity.FlashProductCondition;
import entity.marketingEntity.FlashSaleProduct;
import entity.marketingEntity.FlashSaleProductDTO;
import mapper.marketingMapper.FlashSaleProductMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 朱颢阳
 * @description
 * @time 2024/8/31 23:54
 */
@Service
public class FlashSaleProductServiceImpl implements FlashSaleProductService {
    @Resource
    FlashSaleProductMapper mapper;

    @Override
    public Result getFlashSaleProductDetails(FlashProductCondition flashProductCondition) {
        PageHelper.startPage(flashProductCondition.getCurrentPage(),flashProductCondition.getPageSize());
        Page<FlashSaleProductDTO> page= (Page<FlashSaleProductDTO>) mapper.getFlashSaleProductDetails(flashProductCondition.getActid(), flashProductCondition.getSecid());
        System.out.println(page.getTotal());
        return Result.success((int)page.getTotal(),page.getResult());
    }

    @Override
    public Result addflashproduct(FlashAddCondition condition) {
        List<Integer> list=condition.getProductIds();
        for (Integer integer : list) {
            if (mapper.insertSelective(new FlashSaleProduct(condition.getActid(),condition.getSecid(),integer))<1){
                return Result.failed(500,"添加失败");
            }
        }
        return Result.success("添加成功");
    }

    @Override
    public Result deleteflashproduct(Integer id) {
        if (mapper.deleteByPrimaryKey(id)>0){
            return Result.success("删除成功");
        }else{
            return Result.failed(500,"删除失败");
        }
    }

    @Override
    public Result modifyflashproduct(FlashSaleProduct flashSaleProduct) {
        if (mapper.updateByPrimaryKeySelective(flashSaleProduct)>0){
            return Result.success("修改成功");
        }else{
            return Result.failed(500,"修改失败");
        }
    }
}
